import request from "@/utils/request";
import type{ RoleQuery, RolePageVO, RoleForm } from "./model";
import type { OptionType } from "element-plus/es/components/select-v2/src/select.types.mjs";

 /**
   * 获取角色分页数据
   *
   * @param queryParams
   */

export function getPage(queryParams?:RoleQuery){
    return request({
        url:'/api/v1/roles/page',
        method:'get',
        params:queryParams,
        headers:{
            "Content-Type":"application/x-www-form-urlencoded"
        }
    })
}

/**
   * 获取角色下拉数据源
   *
   * @param queryParams
   */
export function getOptionss(queryParams?:RoleQuery){
    return request<any,OptionType[]>({
        url:'/api/v1/roles/options',
        method:'get',
        params:queryParams,
        headers:{
            "Content-Type":"application/x-www-form-urlencoded"
        }
    })
}

 /**
   * 获取角色的菜单ID集合
   *
   * @param queryParams
   */
 export function getRoleMenuIds(roleId?:number){
    return request<any,number[]>({
        url:'/api/v1/roles/' + roleId + '/menuIds',
        method:'get',
        headers:{
            "Content-Type":"application/x-www-form-urlencoded"
        }
    })
}

/**
   * 分配菜单权限给角色
   *
   * @param queryParams
   */
export function updateRoleMenus(roleId?:number,data:number[]){
    return request({
        url:'/api/v1/roles/' + roleId + '/menus',
        method:'put',
        data:data,
        headers:{
            "Content-Type":"application/json"
        }
    })
}

/**
   * 获取角色表单数据
   *
   * @param id
   */
export function getFormData(id:number){
    return request<any,RoleForm>({
        url:'/api/v1/roles/' + id + '/form',
        method:'get',
        headers:{
            "Content-Type":"application/x-www-form-urlencoded"
        }
    })
}

/**
   * 添加角色
   *
   * @param data
   */
export function add(data:RoleForm){
    return request({
        url:'/api/v1/roles',
        method:'post',
        data:data,
        headers:{
            "Content-Type":"application/json"
        }
    })
}

/**
   * 更新角色
   *
   * @param id
   * @param data
   */
export function update(id:number,data:RoleForm){
    return request({
        url:'/api/v1/roles/' + id,
        method:'put',
        data:data,
        headers:{
            "Content-Type":"application/json"
        }
    })
}

/**
   * 批量删除角色，多个以英文逗号(,)分割
   *
   * @param ids
   */
export function deleteByIds(ids:string){
    return request({
        url:'/api/v1/roles/' + ids,
        method:'delete',
        headers:{
            "Content-Type":"application/x-www-form-urlencoded"
        }
    })
}
